﻿using Models;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class Car_GoodsDAL
    {
        public static List<Car_Goods> getAllDAL(int UserID)
        {
            string sql = string.Format("select c.CarID, c.UserID,c.GoodsID,c.Num,g.GoodsPic,g.GoodsName,g.GoodsPrice,c.[check] from tb_Car c,tb_Goods g where c.GoodsID=g.GoodsID and c.UserID={0}", UserID);
            SqlDataReader dr = DBHelper.GetDataReader(sql);
            List<Car_Goods> list = new List<Car_Goods>();
            while (dr.Read())
            {
                Car_Goods car_Goods = new Car_Goods();
                car_Goods = new Car_Goods();
                car_Goods.CarID = dr.GetInt32(0);
                car_Goods.UserID=dr.GetInt32(1);
                car_Goods.GoodsID = dr.GetInt32(2);
                car_Goods.Num = dr.GetInt32(3);
                car_Goods.GoodsPic = dr.GetString(4);
                car_Goods.GoodsName = dr.GetString(5);
                car_Goods.GoodsPrice = dr.GetDecimal(6);
                car_Goods.check = dr.GetInt32(7) == 1 ? false : true;
                list.Add(car_Goods);
            }
            //关闭读取器
            dr.Close();
            return list;
        }
    }
}
